package com.faxsun.core.persist.dao.impl;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import com.faxsun.core.persist.dao.BannerDao;
import com.faxsun.core.persist.entity.BannerPO;
import mtons.modules.persist.impl.DaoImpl;
import mtons.modules.pojos.Page;

public class BannerDaoImpl extends DaoImpl<BannerPO>implements BannerDao {

	/**
	 * 
	 */
	private static final long serialVersionUID = -3403957384492140609L;

	protected BannerDaoImpl() {
		super(BannerPO.class);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<BannerPO> listDisplayedBanners() {
		Criteria criteria = this.createCriteria();
		criteria.add(Restrictions.eq("isDisplayed", Boolean.TRUE));
		criteria.add(Restrictions.gt("displayOrder", 0));
		criteria.addOrder(Order.asc("displayOrder"));
		return criteria.list();
	}

	@Override
	public List<BannerPO> pageBanners(Page page) {
		PagingQuery<BannerPO> pageQuery = this.pagingQuery(page);
		pageQuery.desc("isDisplayed");
		pageQuery.desc("displayOrder");
		pageQuery.desc("updateTime");
		return pageQuery.list();
	}

}
